﻿@Master['Master'] @Section['Content'] 
<!-- start: Mobile Specific -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- end: Mobile Specific -->

<script>
// On page-load, auto-expand textareas to be tall enough to contain initial content
$(function () {
    $("textarea").each(function () {
	$(this).attr('rows', this.value.split("\n").length);
	});
	      $(".inboxchk").each(function(){
        this.checked=false;
      })    
	        $(".queuechk").each(function(){
        this.checked=false;
      })
	  
$('.row .btn').on('click', function(e) {
    e.preventDefault();
    var $this = $(this);
    var $collapse = $this.closest('.collapse-group').find('.collapse');
    $collapse.collapse('toggle');
});	  
    });
	
window.onload = function () {
    if (location.hash) {
        window.scrollTo(0, 0);
    }
};

$(document).ready(function() {
    if(location.hash) {
        $('a[href=' + location.hash + ']').tab('show');
		//var setactive = $("#heading").data("activetab");
        var a = $(location.hash).addClass("active");
		//console.log(location.hash);
		//$('a[href=' + location.hash + ']').addClass("active in");
    } else {
	var a = $("#home").addClass("active");
	$('a[href=#home]').tab('show');
	}
    $(document.body).on("click", "a[data-toggle]", function(event) {
        location.hash = this.getAttribute("href");
    });
});
$(window).on('popstate', function() {
    var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
    $('a[href=' + anchor + ']').tab('show');
});

$(function () {
//$("#checkAll").click(function(){
  //  $('input:checkbox').not(this).prop('checked', this.checked);
//});


$("#ickbox").click(function(){
    if(this.checked){
      $(".inboxchk").each(function(){
        this.checked=true;
      })              
    }else{
      $(".inboxchk").each(function(){
        this.checked=false;
      })              
    }
  });
  
 $("#qckbox").click(function(){
    if(this.checked){
      $(".queuechk").each(function(){
        this.checked=true;
      })              
    }else{
      $(".queuechk").each(function(){
        this.checked=false;
      })              
    }
  });
});

var inboxarr = new Array();
var queuearr = new Array();
$(function() {
      $("#inboxdelete").click( function()
           {
	var n = $('input:checkbox[id^="inbox"]:checked').length;
//alert(n); // count of checked checkboxes
inboxarr = [];

$('input:checkbox[id^="inbox"]:checked').each(function(){
    console.log($(this).attr("id").replace("inbox_",""));
	inboxarr.push($(this).attr("id").replace("inbox_",""));
	});
	deletemsgs(inboxarr);
           }
      );
});


$(function() {
      $(".actiondelete").click( function()
           {
		   var dataid = $(this).attr("data-id");
		    console.log(dataid);
	//deletemsgs(queuearr);
           }
      );

});
$(function() {
      $(".actionreset").click( function()
           {
		   var dataid = $(this).attr("data-id");
		    console.log(dataid);
	//deletemsgs(queuearr);
           }
      );

});

$(function() {
      $("#queuedelete").click( function()
           {
	var n = $('input:checkbox[id^="queue"]:checked').length;
//alert(n); // count of checked checkboxes
queuearr = [];

$('input:checkbox[id^="queue"]:checked').each(function(){
    console.log($(this).attr("id").replace("queue_", ""))
	queuearr.push($(this).attr("id").replace("queue_", ""));
	});
	deletemsgs(queuearr);
           }
      );

});

function deletemsgs(list)
{
$.post("messages/delete", {dellist : list.join(",") }, function( data ){
 location.reload();
 })
   .error(function() { 

   });
 }

$(function () {
    $(".attachname").each(function () {
	var d = $(this).html();
	var id = this.id
	var dataid = $(this).attr("data-id")
	$(this).html("");
	var attachJson;
	if (d.trim()) {
	attachJson = $.parseJSON(d);
		$.each(attachJson, function(i, item) {
	$('#'+id).append('<li><i class="fa fa-file-text-o mr5"></i><a href="/messages/'+dataid+'/'+ i + '/' +item+'">'+ item +' </a><small class="text-muted"></small></li>');
	
	var attachHide = $("Attachments");
	if (attachHide.attr("data-value") == null) {
	$(this).toggleClass('hide');
	}
});

}
	});
});
	
$(function () {

//$.post("reset.html", {"dude": "test", "boy" : "father"}, {
       // $("span").html(result);
//    });
});

$(document).ready(function(){
    $(".msgbody1").each(function() 
    {
     var oldText = $(this).text();      
     var newText = oldText.replace(/\n/g, "</br>");
     $(this).html(newText);
   });
});

$('#pagination-mail').twbsPagination({
totalPages: 50,
visiblePages: 5
});

$(document).ready(function(){
var page;
var queue;
$("ul").each(function () {
});

   $('.btn-navi-left').click(function(){

	   var id = $(this).parents("ul:first").data("id");
	   var loc = $(this).parents("ul:first").attr("id");
	
	if (loc == "pagination-mail"){
	 parseInt(page = $("#pagination-mail").data("id")) - parseInt(1);
	 queue = $("#pagination-queue").data("id");
	 //console.log("p " + page);
	 if (page > 0)
	   {
	   location.href = "/messages/"+page+"/"+queue+location.hash
	   }
	   } 
	   if (loc == "pagination-queue"){
	   page = $("#pagination-mail").data("id");
	   queue = parseInt($("#pagination-queue").data("id")) - parseInt(1);
	 
	 if (queue > 0)
	   {
		location.href = "/messages/"+page+"/"+queue+location.hash
	   }
	   }
	   
	   
//location.href = "/messages/"+page+"/"+queue
   //console.log("left" + id+loc);
});

   $('.btn-navi-right').click(function(){
  	
	var id = $(this).parents("ul:first").data("id");
	var loc = $(this).parents("ul:first").attr("id");
	
	if (loc == "pagination-mail"){
	page = parseInt($("#pagination-mail").data("id")) + parseInt(1);
	 queue = $("#pagination-queue").data("id");
	 //console.log(queue);
	 if (page > 0)
	   {
	   location.href = "/messages/"+page+"/"+queue+location.hash
	   }
	   } 
	 if (loc == "pagination-queue"){
	   page = $("#pagination-mail").data("id") ;
	 queue = parseInt($("#pagination-queue").data("id")) + parseInt(1);
	 console.log("q " + queue);
	 if (queue > 0)
	   {
	   location.href = "/messages/"+page+"/"+queue+location.hash
	   }
	   }
//location.href = "/messages/"+page+"/"+queue
   //console.log("right " + loc);
});

});

 $( document ).ready(function() {
console.log( "document loaded" );
});
$( window ).load(function() {
console.log( "window loaded " + $("#pageination-mail").data("id"));
});

</script>
<div class="container">
	<div class="row">
		<div class="col-sm-9 col-md-12">
			<!-- Nav tabs -->
			<ul class="nav nav-tabs">
				<li class="">
				<a href="#home" data-toggle="tab">
				<span class="glyphicon glyphicon-inbox">
				</span>
				Emails </a>
				</li>
				<li class="">
				<a href="#queue" data-toggle="tab">
				<span class="glyphicon glyphicon-user">
				</span>
				queue </a>
				</li>
			</ul>
			<!-- Tab panes -->
			<div class="tab-content">
				<div class="tab-pane fade in" id="home">
					<div class="list-group">
						<!-- start: Content -->
						<div class="contentpanel">
						@IfNot.Model.HasMail
						<ul id="pagination-mail" data-id="@Model.Data.CurrentPage" class="pagination-lg pagination"></ul>
<h1>No Email</h1>
						@EndIf
						@If.Model.HasMail
							<div class="row">
								<div class="col-sm-9 col-md-12 col-lg-12">
									<div class="msg-header">
										<div class="pull-right">
										<ul id="pagination-mail" data-id="@Model.Data.CurrentPage" class="pagination-lg pagination">
											 Showing @Model.Data.CurrentPage - @Model.Data.TotalPages of @Model.Data.MailCount items 
											 <button id="mleft" class="btn btn-white btn-navi btn-navi-left ml5" type="button">
											<i class="fa fa-chevron-left"></i></button>
											<button id="mright" class="btn btn-white btn-navi btn-navi-right" type="button">
											<i class="fa fa-chevron-right">
											</i>
											</button>
											</ul>
										</div>
<div class="checkbox-container">
    <input id="ickbox" class="newCheck" type="checkbox">
    <label for="ickbox"><span class="checkBoxTitle"></span>
    </label>
</div>
										<div class="pull-left">
											<div id="All" class="btn btn-white tooltips" data-toggle="tooltip" title="Select All">
											
											</div>
											<button class="btn btn-white tooltips" type="button" data-toggle="tooltip" title="Report Spam">
											<i class="fa fa-exclamation-circle">
											</i>
											</button>
											<button id="inboxdelete" class="btn btn-white tooltips" type="button" data-toggle="tooltip" title="Delete">
											<i class="fa fa-trash-o">
											</i>
											</button>
										</div>
										<!-- pull-right -->
									</div>
									<!-- msg-header -->
									<ul class="media-list msg-list">
										 @Each.Model.Mail
										<li class="media unread">
										<div class="ckbox ckbox-primary pull-left">
											<input class="inboxchk" type="checkbox" id="inbox_@Current.Id">
											<label for="inbox_@Current.Id">
											</label>
										</div>
										<div class="media-body">
											<div class="pull-right media-option">
												 @If.Current.IsAttach
												 <i class="fa fa-paperclip mr5"></i>@EndIf <small>
												@Current.ReceiveDate </small>
												<span>
												<i class="fa fa-star">
												</i>
												</span>
												<div class="btn-group">
													<a class="btn btn-default dropdown-toggle" data-toggle="dropdown">
													<i class="fa fa-cog">
													</i>
													</a>
													<ul class="dropdown-menu pull-right" role="menu">
														<li>
														<a href="#">
														Mark as Unread </a>
														</li>
														<li>
														<a href="#">
														Forward </a>
														</li>
														<li>
														<a href="#">
														Archive </a>
														</li>
														<li>
														<a href="#">
														Delete </a>
														</li>
														<li class="divider">
														</li>
														<li>
														<a href="#">
														Report as Spam </a>
														</li>
													</ul>
												</div>
											</div>
											<h4 class="sender">
											@Current.To </h4>
											<p>
												<span class="msgpop" data-target=".bs-@Current.Id" data-toggle="modal" >
												<strong class="subject">
												@Current.Subject </strong>
												@IfNot.Current.BodyHtml @!Current.SmallBody @EndIf </span>
											</p>
											<div class="modal fade bs-@Current.Id" tabindex="-1" role="dialog">
												<div class="modal-dialog modal-lg">
													<div class="modal-content">
														<div class="modal-header">
															<h4 class="modal-title">
															@Current.Subject </h4>
														</div>
														<div class="modal-body">
															 @Partial['message.html', Current]
														</div>
													</div>
												</div>
											</div>
										</div>
										</li>
										 @EndEach
									</ul>
								</div>
							</div>
							@EndIf
						</div>
						<!-- contentpanel -->
						<!--/.fluid-container-->
						<!-- end: Content -->
					</div>
				</div>
				<div class="tab-pane fade in" id="queue">
					<div class="list-group">
						<div class="contentpanel">
						@Partial['queue.html'] 
							<!--<span class="text-center">
							This tab is empty. </span>-->
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<div class="clearfix">
</div>
@EndSection